﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RegisterPanel : BasePanel<RegisterPanel>
{
    public UIInput inpAccount;
    public UIInput inpPassword;
    public UIButton btnCancel;
    public UIButton btnRegister;
    public override void Init()
    {
        Hide();
        btnCancel.onClick.Add(new EventDelegate(() =>
        {
            Hide();
            LoginPanel.Instance.Show();
        }));
        btnRegister.onClick.Add(new EventDelegate(() =>
        {
            if (inpAccount.value == "")
            {
                TipPanel.Instance.Show("账号不能为空!");
                return;
            }
            if (inpPassword.value == "")
            {
                TipPanel.Instance.Show("密码不能为空!");
                return;
            }
            bool result = AccountMgr.Instance.Register(inpAccount.value, inpPassword.value);
            if (result)
            {
                Hide();
                TipPanel.Instance.Show("注册成功", delegate ()
                {
                    LoginPanel.Instance.Clear();
                    LoginPanel.Instance.Show();
                });
            }
            else
            {
                TipPanel.Instance.Show("账号已存在!");
            }
        }));
    }

    public override void Show()
    {
        base.Show();
        inpAccount.value = "";
        inpPassword.value = "";
    }
}
